package com.bcu.calculus.service.serviceImpl;

import com.bcu.calculus.entity.Flist;
import com.bcu.calculus.entity.Message;
import com.bcu.calculus.utils.SendUtil;
import com.bcu.calculus.mapper.FlistMapper;
import com.bcu.calculus.service.FlistService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class FlistServiceImpl implements FlistService {
    private Logger logger= LoggerFactory.getLogger(getClass());

    @Resource
    private FlistMapper flistMapper;

    @Override
    public Message<?> addFlist(Flist flist) {
        flist.setFlistPostTime(new Date());
        String flistId = "FL" + SendUtil.genSendId();
        flist.setFlistId(flistId);
        logger.info("一级标题-----增加一级标题,flistId为 "+flist.getFlistId());
        return flistMapper.insertSelective(flist) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<?> delFlist(String flistId) {
        logger.info("一级标题-----删除一级标题,flistId为 "+flistId);
        return flistMapper.deleteByPrimaryKey(flistId) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<?> updateFlist(Flist flist) {
        logger.info("一级标题-----修改一级标题,flistId为 "+flist.getFlistId());
        return flistMapper.updateByPrimaryKeySelective(flist) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<Flist> selectOneFlistById(String flistId) {
        logger.info("一级标题-----查询一级标题,flistId为 "+flistId);
        return Message.success(null).add(flistMapper.selectByPrimaryKey(flistId));
    }

    @Override
    public Message<List<Flist>> selectAllFlist() {
        logger.info("一级标题-----查询所有标题");
        return Message.success(null).add(flistMapper.selectAllFlist());
    }

    @Override
    public Message<Flist> selectFlistByName(String flistName) {
        logger.info("一级标题-----通过一级路由名称查询");
        return Message.success(null).add(flistMapper.selectByName(flistName));
    }

    @Override
    public Message<Flist> getFlistBySlistId(String slistid) {
        logger.info("一级路由-----通过二级标题Id查询一级路由,slistId为 "+slistid);
        return Message.success(null).add(flistMapper.getFlistBySlistId(slistid));
    }
}
